//************************************************************************
/// <copyrigth>2024-2025 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// Cross-Platform semaphore for multithreads
///</describe>
/// <date>2024/4/14</date>
///***********************************************************************
#ifndef BSEMAPHORE_H
#define BSEMAPHORE_H

#include "ModuleLoader/ModuleConfig.h"

namespace SystemTool
{
    class CLASS_ITEM BSemaphore
    {
    public:
        // Construct the obj
        BSemaphore(int iCurCnt);

        // Destruct the obj
        ~BSemaphore();

    private:
        // Copy construct
        BSemaphore(const BSemaphore& other) = delete;

        // Assignment
        BSemaphore& operator=(const BSemaphore& other) = delete;

    public:
        // Wait for available resource
        void Acquire(long lMs = 0);

        // Release the resource to be availble
        void Release();

    private:
        // Poco semaphore
        void* m_pSemaphore;

        // Current available resource
        int m_iCurCnt;
    };
}

#endif // BSEMAPHORE_H
